package com.wyp.design.pattern.creational.singleton.container;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

/**
 * @author: yipeng.wang01@hand-china.com-25490
 * @TIME: 2020/2/15/22:47
 **/
public class ContainerInstance {
    /**
     * 通过map进行一个单例对象的管理容器
     */
    private static Map<String, Object> singletonMap = new HashMap<String, Object>();

    /**
     *
     * @param key
     * @param instance
     */
    public static void pushInstance(String key, Object instance) {
        if (StringUtils.isNotBlank(key) && instance != null) {
            //当不包含该key时进行put
            if (!singletonMap.containsKey(key)) {
                singletonMap.put(key, instance);
            }
        }
    }

    public static Object getInstance(String key) {
        return singletonMap.get(key);
    }
}
